<template>
  <div>
    <Modal v-model="isShow" :title="modalTitle" width="700" :mask-closable="false" :closable="false">
      <Form :model="formItem" :label-width="80">
        <FormItem label="活动主题" prop="activity_theme">
          <Input v-model="formItem.activity_theme" placeholder="请输入主题"></Input>
        </FormItem>
        <FormItem label="活动目的" prop="activity_objective">
          <Input v-model="formItem.activity_objective" placeholder="请输入活动目的"></Input>
        </FormItem>
        <FormItem label="活动要求" prop="activity_requirement">
          <Input v-model="formItem.activity_requirement" placeholder="请输入活动要求"></Input>
        </FormItem>
        <FormItem label="活动内容" prop="activity_content">
          <Input v-model="formItem.activity_content" type="textarea" :rows="4" placeholder="请输入活动内容"></Input>
        </FormItem>
      </Form>
      <div slot="footer">
        <Button type="error" @click="cancel">取消</Button>
        <Button type="success" @click="handleSubmit" :loading="btnLoading">保存</Button>
      </div>
    </Modal>
  </div>
</template>

<script>
import { addEditActivityPlan } from '@/api/activity'
export default {
  name: 'ActivityOption',
  props: {
    isShow: {
      type: Boolean,
      default: () => {
        return false
      }
    },
    modalTitle: {
      type: String,
      default: () => {
        return false
      }
    },
    formData: {
      type: Object,
      default: () => {
        return {}
      }
    },
    rowId: {
      type: String,
      default: () => {
        return ''
      }
    }
  },
  data () {
    return {
      formItem: {},
      btnLoading: false
    }
  },
  methods: {
    cancel () {
      this.$emit('cancel')
    },
    handleSubmit () {
      this.btnLoading = true
      const param = {
        id: this.formItem.id,
        activity_theme: this.formItem.activity_theme,
        activity_objective: this.formItem.activity_objective,
        activity_requirement: this.formItem.activity_requirement,
        activity_content: this.formItem.activity_content
      }
      addEditActivityPlan(param).then(ret => {
        let data = ret.data
        if (data.errcode === 0) {
          this.btnLoading = false
          this.success()
          this.$emit('saveHandle')
        } else {
          this.error(data)
          this.btnLoading = false
        }
      })
    },
    success (val) {
      val = this.$common.xeUtils.isEmpty(val) ? '操作成功' : val
      this.$Message.success(val)
    },
    error (data) {
      this.$Message.error({
        content: '操作失败,\n' + data.errmsg
      })
    }
  },
  watch: {
    formData (val) {
      this.formItem = val
    }
  }
}
</script>

<style scoped>
  /deep/ .ivu-modal-header {
    border-bottom: none;
  }

  /deep/ .ivu-modal-footer {
    border-top: none;
  }

  /deep/ .ivu-input {
    width: 80%;
  }
</style>
